home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Peter Lewis / Morpion 1.0.0 / source / PNL Libraries / MyTEUtils < prev    next >
Encoding:
Text File  |  1992-10-05  |  2.0 KB  |  75 lines  |  [TEXT/PJMM]

  1. unit MyTEUtils;
  2.  
  3. interface
  4.  
  5.     function TEEditMenuEnabled (te: TEHandle; static: boolean; maxsize: longInt): boolean;
  6.     procedure TESetEditMenuItem (te: TEHandle; static: boolean; maxsize: longInt; item: integer);
  7.     function TEDoEditMenu (te: TEHandle; static: boolean; maxsize: longInt; item: integer): boolean;
  8.  
  9. implementation
  10.  
  11.     uses
  12.         MyTypes, MyUtils;
  13.  
  14.     function TEEditMenuEnabled (te: TEHandle; static: boolean; maxsize: longInt): boolean;
  15.         var
  16.             i: integer;
  17.     begin
  18.         for i := EMundo to EMselectall do
  19.             TESetEditMenuItem(te, static, maxsize, i);
  20.         TEEditMenuEnabled := GetMHandle(M_Edit)^^.enableFlags <> 0;
  21.     end;
  22.  
  23.     procedure TESetEditMenuItem (te: TEHandle; static: boolean; maxsize: longInt; item: integer);
  24.         var
  25.             offset: longInt;
  26.     begin
  27.         case item of
  28.             EMundo: 
  29.                 SetIDItemEnable(M_Edit, item, false);
  30.             EMcut, EMclear: 
  31.                 SetIDItemEnable(M_Edit, item, not static & (te^^.selStart < te^^.selEnd));  { Can cut,clear if there is a selection }
  32.             EMcopy: 
  33.                 SetIDItemEnable(M_Edit, item, te^^.selStart < te^^.selEnd);  { Can copy iff there is a selection }
  34.             EMpaste: 
  35.                 SetIDItemEnable(M_Edit, item, not static & (GetScrap(nil, 'TEXT', offset) > 0) & (TEGetScrapLen + (te^^.teLength - (te^^.selEnd - te^^.selStart)) < maxsize));
  36.             EMselectall: 
  37.                 SetIDItemEnable(M_Edit, item, te^^.teLength > 0);  { Can select all iff there is something to select }
  38.             otherwise
  39.         end;
  40.     end;
  41.  
  42.     function TEDoEditMenu (te: TEHandle; static: boolean; maxsize: longInt; item: integer): boolean;
  43.         var
  44.             loe, oe: OSErr;
  45.     begin
  46.         TEDoEditMenu := true;
  47.         case item of
  48.             EMcopy:  begin
  49.                 TECopy(te);
  50.                 loe := ZeroScrap;
  51.                 oe := TEToScrap;
  52.                 TEDoEditMenu := false;
  53.             end;
  54.             EMselectall:  begin
  55.                 SetPort(FrontWindow);
  56.                 TESetSelect(0, maxLongInt, te);
  57.                 TEDoEditMenu := false;
  58.             end;
  59.             EMcut:  begin
  60.                 TECut(te);
  61.                 loe := ZeroScrap;
  62.                 oe := TEToScrap;
  63.             end;
  64.             EMclear:  begin
  65.                 TEDelete(te);
  66.             end;
  67.             EMpaste:  begin
  68.                 oe := TEFromScrap;
  69.                 TEPaste(te);
  70.             end;
  71.             otherwise
  72.         end;
  73.     end;
  74.  
  75. end.